package com.ygqh.baby.service.impl;
import java.util.List;
import  com.ygqh.baby.ao.QueryInfo;
import  com.ygqh.baby.ao.ResultSet;
import  com.ygqh.baby.po.YgPublishTag;
import  com.ygqh.baby.mapper.YgPublishTagMapper;
import  com.ygqh.baby.service.YgPublishTagService;
import  org.springframework.util.Assert;
import java.util.Arrays;
import  org.springframework.stereotype.Service;
import  org.springframework.beans.factory.annotation.Autowired;

import  com.ygqh.baby.po.YgPublishTagExample;
import  com.ygqh.baby.ao.DataStatus;

@Service
public class YgPublishTagServiceImpl implements YgPublishTagService{
	
	@Autowired
	private YgPublishTagMapper ygPublishTagMapper;
	
	@Override
	public List<YgPublishTag> find() {
		YgPublishTagExample example = new YgPublishTagExample();
		example.createCriteria().andStatusEqualTo(DataStatus.Valid.name());
		return ygPublishTagMapper.selectByExample(example);
	}

	@Override
	public int findCount() {
		YgPublishTagExample example = new YgPublishTagExample();
		example.createCriteria().andStatusEqualTo(DataStatus.Valid.name());
		return ygPublishTagMapper.countByExample(example);
	}

	@Override
	public YgPublishTag findById(Long id) {
		return ygPublishTagMapper.selectByPrimaryKey(id);
	}


	

	@Override
	public int save(YgPublishTag ygPublishTag) {
		return ygPublishTagMapper.insertSelective(ygPublishTag);
	}

	@Override
	public int update(YgPublishTag ygPublishTag) {
		return ygPublishTagMapper.updateByPrimaryKeySelective(ygPublishTag);
	}

	@Override
	public ResultSet<YgPublishTag> search(QueryInfo queryInfo,String q) {
		List<YgPublishTag>  list =  ygPublishTagMapper.selectSuper(queryInfo, q);
		int count = ygPublishTagMapper.countSuper(q);
		ResultSet<YgPublishTag> resultSet = new ResultSet<YgPublishTag>(count,list);
		return resultSet;
	}

	@Override
	public int deleteSoft(Long[] ids) {
		Assert.notEmpty(ids);
		YgPublishTagExample example = new YgPublishTagExample();
		example.createCriteria().andIdIn(Arrays.asList(ids));
		YgPublishTag record = new YgPublishTag();
		record.setStatus(DataStatus.Delete);
		return ygPublishTagMapper.updateByExampleSelective(record, example);
	}
	
	@Override
	public int deleteSoft(Long id) {
		return this.deleteSoft(new Long[]{id});
	}

	@Override
	public int saveOrUpdate(YgPublishTag ygPublishTag) {
		int r = 0;
		if(ygPublishTag.getId() != null) {
			r = this.update(ygPublishTag);
		}else {
			r = this.save(ygPublishTag);
		}
		return r;
	}

}

